create or replace function deleteDistributor(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 			alias for $1;
		DistributorData		alias for $2;
		
		-- variable for node data
		vIdDistributor 		bigint := null; -- distributor id in database
		vNameDistributor	text := null; 	-- distributor name
		
		-- node path
		vIdNode						varchar(100) := '/distributor/@id';
	begin
		-- get data from xml
		vIdDistributor := cast(extract_value(vIdNode, DistributorData) as bigint);
		
		-- first insert into trace table previous data
		insert into DistributorTrace(idDistributor, nameDistributor)
			select idDistributor, nameDistributor from Distributor dior
				where
					dior.idDistributor = vIdDistributor
		;
		-- second delete row from original table
		delete from Distributor dior
			where
				dior.idDistributor = vIdDistributor;
		executeStatusData := statusCall(successcode(), deleteText());
	end;
$$ language plpgsql VOLATILE;